package org.apache.dolphinscheduler.api.controller;

import com.alibaba.fastjson.JSONObject;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.impl.ExampleDataServicelmpl;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.service.memoryaddress.MemoryAddressService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/exampleData")
public class ExampleDataController extends BaseController{

    private static final Logger logger = LoggerFactory.getLogger(ExampleDataController.class);

    @Autowired
    ExampleDataServicelmpl exampleDataService;
    @Autowired
    MemoryAddressService memoryAddressService;

    @PostMapping(value = "/getColumns")
    @ResponseStatus(HttpStatus.OK)
    //@ApiException(DELETE_USER_BY_ID_ERROR)
    public Object selectByIds(
                              @RequestParam(value = "id") int id,
                              @RequestParam(value = "tag") String tag
    ) throws Exception {
        //logger.info("login user {}, delete user, userId: {},", loginUser.getUserName(), id);
        JSONObject resultJsonarray = new JSONObject();
        Map<String, Object> result =exampleDataService.selectByNodeId(id,tag);
        /*if (result.get(Constants.STATUS) != Status.SUCCESS) {
            return returnDataList(result);
        }*/
        return returnDataList(result);
    }


    @GetMapping(value = "/getList")
    @ResponseStatus(HttpStatus.OK)
    //@ApiException(DELETE_USER_BY_ID_ERROR)
    public Object selectList() throws Exception {
        //logger.info("login user {}, delete user, userId: {},", loginUser.getUserName(), id);

        Map<String, Object> result =exampleDataService.selectList();
        /*if (result.get(Constants.STATUS) != Status.SUCCESS) {
            return returnDataListPaging(result);
        }*/

        return returnDataList(result);
    }

    @PostMapping(value = "/getResult")
    @ResponseStatus(HttpStatus.OK)
    //@ApiException(DELETE_USER_BY_ID_ERROR)
    public Object getResult(@RequestParam(value = "id") int id

    ) throws Exception {
        //logger.info("login user {}, delete user, userId: {},", loginUser.getUserName(), id);
        Map<String, Object> result =exampleDataService.showResult(id);
        /*if (result.get(Constants.STATUS) != Status.SUCCESS) {
            return returnDataListPaging(result);
        }*/
        return returnDataList(result);
    }

}
